package com.example.multi.util;

import cn.hutool.core.util.NumberUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class WebUtil {

    public static HttpServletRequest getRequest(){
        return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
    }

    public static HttpServletResponse getResponse(){
        return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getResponse();
    }

    public static String getCurrentRequestHeaderToken(){
        try {
            HttpServletRequest request = getRequest();
            if(request!=null){
                String token = request.getHeader("token");
                return token;
            }
        }catch (Exception e){
            log.debug("getCurrentRequestHeaderToken:{}",e);
        }
        return null;
    }

}
